/**********************************************************************************************************************
 * The contents of this file are subject to the SugarCRM Public License Version 1.1.3 ("License"); You may not use this
 * file except in compliance with the License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
 * express or implied.  See the License for the specific language governing rights and limitations under the License.
 *
 * All copies of the Covered Code must include on each user interface screen:
 *    (i) the "Powered by SugarCRM" logo and
 *    (ii) the SugarCRM copyright notice
 *    (iii) the SplendidCRM copyright notice
 * in the same form as they appear in the distribution.  See full license for requirements.
 *
 * The Original Code is: SplendidCRM Open Source
 * The Initial Developer of the Original Code is SplendidCRM Software, Inc.
 * Portions created by SplendidCRM Software are Copyright (C) 2005 SplendidCRM Software, Inc. All Rights Reserved.
 * Contributor(s): ______________________________________.
 *********************************************************************************************************************/
using System;
using System.Data;
using System.Data.Common;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
//using Microsoft.VisualBasic;

namespace SplendidCRM.Home
{
	/// <summary>
	/// Summary description for Default.
	/// </summary>
	public class Default : SplendidPage
	{
		protected Label       lblUpgradeWarning;
		protected PlaceHolder plcSubPanelLeft  ;
		protected PlaceHolder plcSubPanelBody  ;
		protected PlaceHolder plcSubPanelRight ;

		private void Page_Load(object sender, System.EventArgs e)
		{
			SetPageTitle(L10n.Term(".LBL_BROWSER_TITLE"));
			if ( !IsPostBack )
			{
				// 01/15/2008 Paul.  Move the Upgrade warning to an exclusive location on the home page. 
				// We want to reduce the performance hit to a single page. 
				if ( Security.IS_ADMIN )
				{
					string sAvailableVersion = Sql.ToString(Application["available_version"]);
					if ( !Sql.IsEmptyString(sAvailableVersion) )
					{
						Version vSplendidVersion  = new Version(Sql.ToString(Application["SplendidVersion"]));
						Version vAvailableVersion = new Version(sAvailableVersion);
						if ( vSplendidVersion < vAvailableVersion )
						{
							lblUpgradeWarning.Text = L10n.Term("Administration.WARN_UPGRADE") + sAvailableVersion + ": " + Sql.ToString(Application["available_version_description"]);
							lblUpgradeWarning.Visible = true;
						}
					}
				}
				// 09/09/2007 Paul.  We are having trouble dynamically adding user controls to the WebPartZone. 
				// Instead, control visibility in the user control.  This approach as the added benefit of hiding the 
				// control even if the WebPartManager has moved it to an alternate zone. 
				// This approach is far from idea as it leaves web part frames in tact. 
				/*
				WebPartManager mgrWebPart = Page.Master.FindControl("mgrWebPart") as WebPartManager;
				Control ctl = LoadControl("~/Leads/MyLeads.ascx");
				GenericWebPart part = mgrWebPart.CreateWebPart(ctl);
				mgrWebPart.AddWebPart(part, zBody, 0);
				*/

				// 02/11/2007 Paul.  Only show team notices if team management enabled. 
				// 01/17/2008 Paul.  The MyTeamNotices control will hide itself. 
				// ctlMyTeamNotices.Visible = Crm.Config.enable_team_management();
				// 01/22/2007 Paul.  The ZoneTemplate does not seem to allow data binding to the title, so do it manually. 
				// 01/11/2008 Paul.  Remove the side bar. 
				/*
				foreach ( WebPart part in zSidebar.WebParts )
				{
					part.Title = L10n.Term(part.Title);
				}
				*/
				// 01/22/2007 Paul.  The ZoneTemplate does not seem to allow data binding to the title, so do it manually. 
				// 01/17/2008 Paul.  We are replacing WebParts with a DetailView relationship. 
				/*
				foreach ( WebPart part in zBody.WebParts )
				{
					part.Title = L10n.Term(part.Title);
				}
				// 01/22/2007 Paul.  The ZoneTemplate does not seem to allow data binding to the title, so do it manually. 
				foreach ( WebPart part in zRightbar.WebParts )
				{
					part.Title = L10n.Term(part.Title);
				}
				*/
				// 06/09/2006 Paul.  The primary data binding will now only occur in the ASPX pages so that this is only one per cycle. 
				Page.DataBind();
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			SetMenu("Home");
			this.Load += new System.EventHandler(this.Page_Load);
			// 01/20/2007 Paul.  Use WebParts to display the relationships. 
			// 01/17/2008 Paul.  We are replacing WebParts with a DetailView relationship. 
			this.AppendDetailViewRelationships("Home.DetailView.Left" , plcSubPanelLeft );
			this.AppendDetailViewRelationships("Home.DetailView.Body" , plcSubPanelBody );
			this.AppendDetailViewRelationships("Home.DetailView.Right", plcSubPanelRight);
		}
		#endregion
	}
}
